package com.example.serviceverificationcode.controller;

import com.example.internalcommon.dto.ResponseResult;
import com.example.internalcommon.response.NumberCodeResponse;
import net.sf.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author lyra
 * @Date 2023/4/3 11:49
 **/
@RestController
public class NumberCodeController {

    /**
     * 2.数字验证码服务
     * @param size
     * @return
     */
    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size) {
        System.out.println("size" + size);
        //生成验证码
        double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10, size - 1));
        System.out.println(mathRandom);
        int resultInt = (int) mathRandom;
        System.out.println("generator src code"+resultInt);

        // 定义返回值
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(resultInt);

        return ResponseResult.success(response);

    }

    public static void main(String[] args) {
        // 1.获取随机数
        double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10, 5));
        System.out.println(mathRandom);
        int resultInt = (int) mathRandom;
        System.out.println(resultInt);
        // 2.
    }
}
